package jk.spider.util;

import java.util.HashSet;
import java.util.Set;

public class URLCache {

	protected static Set<String> urlCache;
	protected static Set<String> msCache;
	
	static {
		urlCache = new HashSet<String>();
		msCache = new HashSet<String>();
	}
	
	public static synchronized boolean findUrlInCache(String url) {
		url = url.trim();
		if(urlCache.contains(url) || msCache.contains(url))
			return true;
		else {
			if(urlCache.size() > 15000)
				urlCache.remove(0);
			urlCache.add(url);
		}
		return false;
	}
	
	public static synchronized void inCache(String[][] urlInfo) {
		if(urlInfo.length > 0) {
			for(int i = 0; i < urlInfo.length; i++) {
				msCache.add(urlInfo[i][0].trim());
			}
		}
	}
}
